package com.tecklab.demo.controller;

import com.tecklab.demo.common.Result;
import com.tecklab.demo.dto.EmployeeDTO;
import com.tecklab.demo.param.EmployeeAddParam;
import com.tecklab.demo.param.EmployeeModifyParam;
import com.tecklab.demo.service.EmployeeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @GetMapping("/getById")
    public EmployeeDTO getById(@RequestParam Integer id) {

        return employeeService.getById(id);

    }

    /**
     * 查询所有医护工作者
     * @return
     */
    @GetMapping("/getList")
    public List<EmployeeDTO> getList() {

        return employeeService.getList();

    }

    /**
     * 根据部门id查询该部门下所有员工
     * @param departmentId
     * @return
     */
    @GetMapping("/getListByDeptId")
    public List<EmployeeDTO> getByDepartmentId(@RequestParam Integer departmentId) {

        return employeeService.getByDepartmentId(departmentId);

    }

    @PostMapping("/create")
    public Result<Integer> create(@RequestBody EmployeeAddParam addParam) {
        return Result.success(employeeService.create(addParam));
    }

    @PostMapping("/modify")
    public Result<Integer> modify(@RequestBody EmployeeModifyParam modifyParam) {
        return Result.success(employeeService.modify(modifyParam));
    }

    @GetMapping("/deleteByName")
    public Result<Integer> deleteByName(@RequestParam String name) {
        return Result.success(employeeService.deleteByName(name));
    }

}
